package com.wolfman.socket.server.mapper.impl;

import com.wolfman.socket.server.mapper.LogMapper;
import com.wolfman.socket.server.pojo.Log;
import com.wolfman.socket.server.util.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * @Title
 * @Description
 * @Author WolfMan
 * @Date 2022/11/26 17:38
 * @Email 2370032534@qq.com
 */
public class LogMapperImpl implements LogMapper {

    @Override
    public Object saveLog(Log log) {
        PreparedStatement statement = null;
        Connection connection = JDBCUtils.getConnection();
        try {
            String sql = "insert into log(method,message,content,datetime) values(?,?,?,?)";
            statement = connection.prepareStatement(sql);
            statement.setString(1, log.getMethod());
            statement.setString(2, log.getMessage());
            statement.setString(3, log.getContent());
            statement.setObject(4, log.getDateTime());
            statement.execute();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JDBCUtils.close();
            JDBCUtils.close(statement);
        }
        return false;
    }

}
